# coding: UTF-8
# Filename : chain_category_api.py
# Company : imedia
# Author : rose
# -*-coding:utf-8 -*-
from api.common.common import *
from api.common import mysql,log,utils,httputils,const,xml_tpl,err_tpl

from django.http import HttpResponse
import chain_category_data_model
'''
http://api.imedia.com/app/part/list
'''
		
#details list
def chain_category_list(request):
    #record log((frist action))
    httputils.footprint(request)
    #param
    cus_id = httputils.post(request, 'cus_id')#is customer id,more
    if not utils.is_num(cus_id): cus_id = 20
    #Verification
    if validate(request):
        return validate(request)
    #models
    output = '' 
    output += chain_category_data_model.imedia_start 
    output += get_body_str(cus_id)
    output += chain_category_data_model.imedia_end
    return response(output)

#获取中间数据体
def get_body_str(cus_id):
    #sql
    sql = '''
    SELECT class_name FROM p_class 
    where cus_id = %s 
    order by sort 
    '''
    #获取起始行
    param = [int(cus_id)]
    rsts = mysql.doSearch(sql, param)
    body_str = ''
    for obj in rsts:
        body_template = chain_category_data_model.imedia_body
        body_template = body_template.replace('{name}', str(obj[0]))
        body_str += body_template
    return body_str



